package NC;

import java.util.ArrayList;

public class NC45 {
    private final ArrayList<Integer> pre=new ArrayList<>();
    private final ArrayList<Integer> mid=new ArrayList<>();
    private final ArrayList<Integer> post=new ArrayList<>();
    public int[][] threeOrders (TreeNode root) {
        // write code here
        int[][] ans = new int[3][];
        bfs(root);
        ans[0] = pre.stream().mapToInt(Integer::intValue).toArray();
        ans[1] = mid.stream().mapToInt(Integer::intValue).toArray();
        ans[2] = post.stream().mapToInt(Integer::intValue).toArray();

        return ans;
    }
    public void bfs(TreeNode root){
        if(root==null) return;
        pre.add(root.val);
        bfs(root.left);
        mid.add(root.val);
        bfs(root.right);
        post.add(root.val);
    }
}
